﻿using System;
using App.Entity;
using App.IServices;
using App.IRepository;
using System.Collections.Generic;

/*!
* 文件描述：一切从简，只为了更懒！
*/
namespace App.Services
{
	public partial class Sys_OrganizeServices : BaseServices<Sys_Organize> , ISys_OrganizeServices
	{
		ISys_OrganizeRepository _ISys_OrganizeRepository;
		public Sys_OrganizeServices(ISys_OrganizeRepository __ISys_OrganizeRepository)
		{
			this._ISys_OrganizeRepository = __ISys_OrganizeRepository;
			base._IBaseRepository = __ISys_OrganizeRepository;
		}

        public void DeleteForm(string keyValue)
        {
            if (_ISys_OrganizeRepository.QueryCount(t => t.ParentId.Equals(keyValue)) > 0)
            {
                throw new Exception("删除失败！操作的对象包含了下级数据。");
            }
            else
            {
                _ISys_OrganizeRepository.Delete(t => t.Id == keyValue);
            }
        }

        public Sys_Organize GetForm(string keyValue)
        {
            return _ISys_OrganizeRepository.QuerySingle(c=>c.Id== keyValue);
        }

        public List<Sys_Organize> GetList()
        {
           return _ISys_OrganizeRepository.QueryByWhere(c=>true,"CreatorTime");
        }

        public void SubmitForm(Sys_Organize organizeEntity, string keyValue)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                organizeEntity.Modify(keyValue);
                _ISys_OrganizeRepository.Update(organizeEntity);
            }
            else
            {
                organizeEntity.Create();
                _ISys_OrganizeRepository.Insert(organizeEntity);
            }
        }
    }
}